<%--
  Created by IntelliJ IDEA.
  User: ykq
  Date: 2024/6/5
  Time: 10:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <%--引入elementui的css样式--%>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <%--引入vue文件:必须先引入vue--%>
    <script src="https://unpkg.com/vue@2/dist/vue.js"></script>
    <%--引入elementui的js文件--%>
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <%--引入axios--%>
    <script src="/js/axios.min.js"></script>
</head>
<body>
<div id="app">
    <el-card class="box-card">
        <el-form :inline="true" :model="empSearchForm" class="demo-form-inline">
            <el-form-item label="用户名称">
                <el-input v-model="empSearchForm.ename" placeholder="请输入用户名称"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit" icon="el-icon-search">搜索</el-button>
                <el-button type="primary" @click="onSubmit" icon="el-icon-refresh">刷新</el-button>
                <el-button type="primary" @click="onSubmit" icon="el-icon-circle-plus-outline">添加</el-button>
            </el-form-item>
        </el-form>
        <el-table
                :data="tableData"
                border
                style="width: 100%">
            <el-table-column
                    prop="ename"
                    label="用户名"
                    >
            </el-table-column>
            <el-table-column
                    prop="gmtCreate"
                    label="入职时间"
                    width="220"
                    >
            </el-table-column>
            <el-table-column
                    prop="gmtModified"
                    width="220"
                    label="修改时间"
            >
            </el-table-column>
            <el-table-column
                    prop="telephone"
                    label="手机号">
            </el-table-column>
            <el-table-column
                    prop="age"
                    label="年龄">
            </el-table-column>
            <el-table-column
                    prop="role.roleName"
                    label="角色">
            </el-table-column>
            <el-table-column
                    prop="state"
                    label="状态">
                <template slot-scope="scope">
                     <el-tag :type="scope.row.state===0?'success':scope.row.state===1?'info':'danger'">
                         {{scope.row.state===0?'在职':scope.row.state===1?'离职':'冻结'}}
                     </el-tag>
                </template>
            </el-table-column>
            <el-table-column
                    label="操作">
                <template slot-scope="scope">
                    <el-button type="primary" size="small">编辑</el-button>
                    <el-button type="primary" size="small">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <%--分页组件--%>
        <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="currentPage"
                :page-sizes="[5, 10, 15, 20]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
        </el-pagination>
    </el-card>
</div>
</body>
<script>
    let app = new Vue({
        el: "#app",
        data: {
            empSearchForm: {},
            tableData: [],
            currentPage:1,
            pageSize:5,
            total:0,
        },
        created() {
            this.loadTable();
        },
        methods: {
            loadTable(){
               axios.post("/empinfo/list?current="+this.currentPage+"&pageSize="+this.pageSize,this.empSearchForm).then(result=>{
                    this.tableData=result.data.data.list;
                    this.total=result.data.data.total;
               })
            },
            //搜索
            onSubmit(){
               this.currentPage=1;
               this.loadTable();
            },
            handleSizeChange(val){
                this.pageSize=val;
                this.loadTable()
            },
            handleCurrentChange(val){
                this.currentPage=val;
                this.loadTable()
            },
        }
    })
</script>
</html>
